﻿using System.Linq;
using DAL;
using DataContext;
using Entity;
using Utils;

namespace BLL
{
    public class CtrPermission
    {
        /// <summary>
        /// Thêm mới một Permission
        /// </summary>
        /// <param name="adminID"></param>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public int InsertPermission(int adminID, int roleID)
        {
            return DB.AdminInstance.uspPermissionInsert(adminID, roleID);
        }

        /// <summary>
        /// Thêm mới nhiều admin vào một Role
        /// </summary>
        /// <param name="adminIDs"></param>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public int InsertPermissionMultiAdminToRole(string adminIDs, int roleID)
        {
            var ret = "";
            return DB.AdminInstance.uspPermissionInsertMultiAdminToRole(roleID, adminIDs, ref ret);
        }

        /// <summary>
        /// Xóa một Permission
        /// </summary>
        /// <param name="permissionID"></param>
        /// <returns></returns>
        public int DeletePermission(int permissionID)
        {
            return DB.AdminInstance.uspPermissionDelete(permissionID);
        }

        /// <summary>
        /// Xóa nhiều Permission đồng thời
        /// </summary>
        /// <param name="permissionIDs"></param>
        /// <returns></returns>
        public int DeletePermissionMulti(string permissionIDs)
        {
            return DB.AdminInstance.uspPermissionDeleteMulti(permissionIDs);
        }

        /// <summary>
        /// Lấy danh sách Admin thuộc Role
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public ClassExtend<int, uspPermissionGetListAdminInRoleResult> GetListAdminInRole(int roleID)
        {
            var objReturn = new ClassExtend<int, uspPermissionGetListAdminInRoleResult>
                                {Items = DB.AdminInstance.uspPermissionGetListAdminInRole(roleID).ToList()};
            objReturn.TotalRecord = objReturn.Items.Count;
            objReturn.Info = 0;
            return objReturn;
        }

        /// <summary>
        /// Lấy danh sách Admin không thuộc Role
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public ClassExtend<int, uspPermissionGetListAdminNotInRoleResult> GetListAdminNotInRole(int roleID)
        {
            var objReturn = new ClassExtend<int, uspPermissionGetListAdminNotInRoleResult>
                                {Items = DB.AdminInstance.uspPermissionGetListAdminNotInRole(roleID).ToList()};
            objReturn.TotalRecord = objReturn.Items.Count;
            objReturn.Info = 0;
            return objReturn;
        }

        /// <summary>
        /// Lấy danh sách Role của của Admin
        /// </summary>
        /// <param name="adminID"></param>
        /// <returns></returns>
        public ClassExtend<int, uspPermissionGetListRoleInAdminResult> GetListRoleInAdmin(int adminID)
        {
            var objReturn = new ClassExtend<int, uspPermissionGetListRoleInAdminResult>
            {
                Items = DB.AdminInstance.uspPermissionGetListRoleInAdmin(AdminUtils.ServicesID, adminID).ToList()
            };
            objReturn.TotalRecord = objReturn.Items.Count;
            objReturn.Info = 0;
            return objReturn;
        }

        /// <summary>
        /// Lấy danh sách Role không thuộc Admin
        /// </summary>
        /// <param name="adminID"></param>
        /// <returns></returns>
        public ClassExtend<int, uspPermissionGetListRoleNotInAdminResult> GetListRoleNotInAdmin(int adminID)
        {
            var objReturn = new ClassExtend<int, uspPermissionGetListRoleNotInAdminResult>
            {
                Items = DB.AdminInstance.uspPermissionGetListRoleNotInAdmin(AdminUtils.ServicesID, adminID).ToList()
            };
            objReturn.TotalRecord = objReturn.Items.Count;
            objReturn.Info = 0;
            return objReturn;
        }
    }
}
